import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDEquipmentStrengthen {
	/**星级*/
	id,
	/**升级概率--符号下限<=x<=上限*/
	upgradeRate,
	/**不变概率*/
	remainRate,
	/**降级概率*/
	degradeRate,
	/**降低范围*/
	degradeRange,
	/**精炼消耗道具*/
	costItem,
	/**精炼消耗*/
	costNum,
	/**强化加成比例*/
	strengthenAdd,
	/**熔炼返回值*/
	smeltNum,

	/**枚举数量*/
	EnumCount
}



export class CDEquipmentStrengthen{
	/**星级*/
	public id: number;
	/**升级概率--符号下限<=x<=上限*/
	public upgradeRate: number[];
	/**不变概率*/
	public remainRate: number[];
	/**降级概率*/
	public degradeRate: number[];
	/**降低范围*/
	public degradeRange: number[];
	/**精炼消耗道具*/
	public costItem: number;
	/**精炼消耗*/
	public costNum: number;
	/**强化加成比例*/
	public strengthenAdd: number;
	/**熔炼返回值*/
	public smeltNum: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDEquipmentStrengthen.id: return this.id;
			case E_CDEquipmentStrengthen.upgradeRate: return this.upgradeRate;
			case E_CDEquipmentStrengthen.remainRate: return this.remainRate;
			case E_CDEquipmentStrengthen.degradeRate: return this.degradeRate;
			case E_CDEquipmentStrengthen.degradeRange: return this.degradeRange;
			case E_CDEquipmentStrengthen.costItem: return this.costItem;
			case E_CDEquipmentStrengthen.costNum: return this.costNum;
			case E_CDEquipmentStrengthen.strengthenAdd: return this.strengthenAdd;
			case E_CDEquipmentStrengthen.smeltNum: return this.smeltNum;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDEquipmentStrengthen.id: this.id = v; break;
			case E_CDEquipmentStrengthen.upgradeRate: this.upgradeRate = v; break;
			case E_CDEquipmentStrengthen.remainRate: this.remainRate = v; break;
			case E_CDEquipmentStrengthen.degradeRate: this.degradeRate = v; break;
			case E_CDEquipmentStrengthen.degradeRange: this.degradeRange = v; break;
			case E_CDEquipmentStrengthen.costItem: this.costItem = v; break;
			case E_CDEquipmentStrengthen.costNum: this.costNum = v; break;
			case E_CDEquipmentStrengthen.strengthenAdd: this.strengthenAdd = v; break;
			case E_CDEquipmentStrengthen.smeltNum: this.smeltNum = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDEquipmentStrengthen> = new HashMap<number, CDEquipmentStrengthen>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDEquipmentStrengthen[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDEquipmentStrengthen();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].upgradeRate = [];
			const attrArray = list[i].upgradeRate;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].remainRate = [];
			const attrArray = list[i].remainRate;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].degradeRate = [];
			const attrArray = list[i].degradeRate;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].degradeRange = [];
			const attrArray = list[i].degradeRange;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].costItem = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].strengthenAdd = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].smeltNum = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDEquipmentStrengthen{
		return this.datas ? this.datas.get(id) : null;
	}
}
